package com.gg.admin.goods.contorller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import com.gg.admin.goods.service.GoodsService;
import com.github.pagehelper.PageInfo;

import helpers.baseservlet.BaseServlet;
import povos.Goods;

@WebServlet("/admin/AdminRemoveGoodByFidServlet")
public class AdminRemoveGoodByFidServlet extends BaseServlet {
	@Autowired
	private GoodsService goodsService;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		Integer fid = Integer.parseInt(request.getParameter("fid"));
		
		goodsService.removeGoodsByFid(fid);
		@SuppressWarnings("unchecked")
		PageInfo<Goods> info = (PageInfo<Goods>) request.getSession().getAttribute("goodsinfo");
		List<Goods> goods = info.getList();
		for (Goods g : goods) {
			if (fid == g.getFid()) {
				goods.remove(g);
				break;
			}
		}
		info.setList(goods);
		request.getSession().setAttribute("goodsinfo", info);
		response.sendRedirect("/fruits/BSindex4.jsp");
		
		
	}

}
